package com.nativetalk.common.getui;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.payload.APNPayload;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import com.nativetalk.common.Constants;

/**
 * Created by lizhun on 16/1/12.
 */
public class IosJGetuiUtil {
    static String appId = Constants.teacher_appId;
    static String appKey = Constants.teacher_appKey;
    static String masterSecret = Constants.teacher_masterSecret;
    //    static String appId = Constants.student_appId;
//    static String appKey = Constants.student_appKey;
//    static String masterSecret = Constants.student_masterSecret;
    static String url = Constants.getui_url;
    //使用https的域
  //  static String url = "https://api.getui.com/apiex.htm";
    public static void apnpush(String title,String body,String devicetoken,int stt_id
            ,String memb_name,String memb_head_portrait)  {
        TransmissionTemplate template = new TransmissionTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTransmissionType(2);        //应用启动类型，1：强制应用启动 2：等待应用启动

        System.out.println(1);

        //APN高级推送
        APNPayload apnpayload = new APNPayload();
        APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
        alertMsg.setBody(body);
        //IOS8.2支持字段
        alertMsg.setTitle(title);

        apnpayload.setAlertMsg(alertMsg);
        apnpayload.setContentAvailable(4);//透传数据
        apnpayload.setBadge(2);
//        apnpayload.addCustomMsg("memb_name",memb_name);
//        apnpayload.addCustomMsg("stt_id",stt_id);
//        apnpayload.addCustomMsg("memb_head_portrait",memb_head_portrait);
        template.setAPNInfo(apnpayload);

        IGtPush push = new IGtPush(url, appKey, masterSecret);


        SingleMessage message = new SingleMessage();
        message.setData(template);

        IPushResult pushResult = push.pushAPNMessageToSingle(appId,devicetoken,message);
        System.out.println();
        System.out.println(pushResult.getResponse());

    }

    public static void main(String[] args) throws Exception {
//        IosMessageTeacher.apnpush("f8b52a0916974434134c21ed1aaef78a783eb401a1843076b3dc87d7ff3f86d5",0);
//
//       IosMessageStudent.apnpush(
//               "f917001230c1df83a7540f6955c24d0a8eada28b08c7935651d14ee7c7106cbe",0);
    }
}
